<template>
  <el-dialog :title="itemObj.name" :visible.sync="diaOpen" :close-on-click-modal="false" width="1000px" append-to-body @close="diaOpen=false">
    <el-table v-loading="loading" :data="tableList" style="border: 1px solid #e6ebf5;" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="名称" align="center" prop="_NAME" />
      <!--<el-table-column label="名称" align="center" prop="PS_RK_XQBT" />-->
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="saveBtn">保 存</el-button>
      <el-button @click="diaOpen=false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { selectKnowLedge } from "@/api/form/data"
export default {
  name: "department",
  dicts: [],
  props: {
    _open: {
      type: Boolean,
      default: false,
    },
    itemObj: {
      type: Object,
      default: {}
    }
  },
  components: {},
  data () {
    return {
      selectedDatas: [],
      // 表格数据
      tableList: [],
      // 遮罩层
      loading: true,
      diaOpen: this._open,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: "",
        modelFlag: 0
      },
      total: 0,
    };
  },
  watch: {

  },
  created () {
    this.getList()
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.selectedDatas = selection
    },
    getList () {
      // 后续扩展-目前仅涉及到知识库和材料库
      if (this.itemObj.name == '知识库选择') {
        this.queryParams['tpl'] = 'root_knowledge'
      } else {
        this.queryParams['tpl'] = 'root_material'
      }
      selectKnowLedge(this.queryParams).then(response => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    saveBtn () {
      this.$emit("saveData", this.selectedDatas)
      this.diaOpen = false
    }
  },
};
</script>
